/**
 * 
 */
package ptvv.sample;

import ptvv.*;

/**
 * @author dkz
 * 
 */
public class Ran extends DefaultAutomata {
	protected OutputPort outputPort2;
	// variables needed for computation
	String message;

	public Ran(DefaultAutomata destination, Thread dest,
			DefaultAutomata destination2, Thread dest2) {
		this.setName("Ran");

		outputPort = new OutputPort(destination, dest);
		outputPort2 = new OutputPort(destination2, dest2);

	}

	public void starting() throws InterruptedException {
		String item = eventQueue.take(); // waiting for start
		//System.out.println(item);
		//logger.log("Waiting");

	}

	public void ready() throws InterruptedException {
		message = inputPort.take();
	}

	public void running() throws InterruptedException {
		message = (int) (Math.random() * Integer.parseInt(message)) + "";
		// System.out.println("sleeping..");
		// System.out.println("awake");
		// this.internalState = InternalStates.Suspended;
	}

	public void suspended() throws InterruptedException {

	}

	public void end() {
		// System.out.println("end");
		logger.log(this.getName() + ": " + message);
		outputPort.destAutomata.addInput(message);
		outputPort2.destAutomata.addInput("5");

		// System.out.println(outputPort.destination.internalState);

		// System.out.println(outputPort.destination.isInterrupted());

		outputPort.destAutomata.addEvent("START");
		outputPort2.destAutomata.addEvent("START");
		repeatBool = true;
	}

	public void dead() {
		// this.internalState = InternalStates.Start;

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}

}
